Skip to content

Fix file utilities and add basic tests#4960

Closed
njzjz wants to merge 1 commit into
develfrom
codex/fix-spelling-error-and-improve-tests
Closed

Fix file utilities and add basic tests#4960
njzjz wants to merge 1 commit into
develfrom
codex/fix-spelling-error-and-improve-tests

Conversation

@njzjz
Copy link
Copy Markdown
Member

@njzjz njzjz commented Sep 4, 2025

Summary

  • correct label mismatch wording in training docs
  • fix Fio.get_file_list path check and improve text file helpers
  • add regression tests for file utilities

Testing

  • pre-commit run --files doc/model/train-fitting-tensor.md deepmd/tf/nvnmd/utils/fio.py source/tests/tf/test_fio_utils.py
  • PYTHONPATH=$PWD pytest source/tests/tf/test_fio_utils.py (fails: ModuleNotFoundError: No module named 'deepmd.about')

https://chatgpt.com/codex/tasks/task_e_68b3566011908323bb35035b903814f0

Summary by CodeRabbit

  • New Features
    • Text saving now accepts either a single string or a list, with smarter default handling.
  • Bug Fixes
    • Directory file listing works reliably, skipping non-existent paths and correctly traversing existing folders.
  • Refactor
    • Default values for text load/save are standardized for more predictable behavior.
  • Documentation
    • Corrected grammar in training tensor documentation.
  • Tests
    • Added tests covering directory listing behavior and default return values when loading missing text files.

Copilot AI review requested due to automatic review settings September 4, 2025 05:36
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This pull request fixes file utilities in the NVNMD module and adds basic regression tests. The changes address a bug in path checking logic and improve the robustness of text file handling methods.

  • Fixes a critical bug in Fio.get_file_list where self.is_path was called without arguments
  • Improves documentation and parameter handling in FioDic and FioTxt classes
  • Adds comprehensive test coverage for the fixed file utility functions

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
deepmd/tf/nvnmd/utils/fio.py Fixes get_file_list path check bug and improves text file utility methods with better documentation and default parameter handling
source/tests/tf/test_fio_utils.py Adds new test file with regression tests for Fio.get_file_list and FioTxt.load methods
doc/model/train-fitting-tensor.md Corrects grammar in error message documentation from "mismatch it's name" to "mismatches its name"
Comments suppressed due to low confidence (1)

deepmd/tf/nvnmd/utils/fio.py:204

  • The parameter type annotation list | str | None lacks specificity for the list type. Consider using list[str] | str | None to clearly indicate that the list should contain strings, which matches the function's behavior of converting strings to lists and adding newlines.
    def save(self, file_name: str = "", data: list | str | None = None) -> None:

@njzjz njzjz closed this Sep 4, 2025
@njzjz njzjz deleted the codex/fix-spelling-error-and-improve-tests branch September 4, 2025 05:36
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Sep 4, 2025

Caution

Review failed

The pull request is closed.

📝 Walkthrough

Walkthrough

Updates deepmd/tf/nvnmd/utils/fio.py to fix a directory check in Fio.get_file_list and modifies FioTxt.load/save signatures and default handling. Adds tests for these behaviors. Edits a documentation sentence for grammar.

Changes

Cohort / File(s) Summary
FIO utilities (logic and API)
deepmd/tf/nvnmd/utils/fio.py
Fixes get_file_list to call self.is_path(path) when deciding to traverse; changes FioTxt.load default from [] to None and normalizes to []; changes FioTxt.save default data to None, accepts `list
Tests
source/tests/tf/test_fio_utils.py
Adds tests for Fio.get_file_list directory traversal and non-existent path behavior; adds test ensuring FioTxt.load returns an empty list when file is missing.
Docs
doc/model/train-fitting-tensor.md
Fixes grammar in an error message example.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor Caller
  participant Fio
  participant FS as FileSystem

  rect rgba(230,240,255,0.5)
  note over Caller,Fio: Fio.get_file_list(path)
  Caller->>Fio: get_file_list(path)
  Fio->>Fio: is_path(path)?
  alt path exists and is dir
    Fio->>FS: listdir(path) / recurse
    FS-->>Fio: entries
    Fio-->>Caller: [file paths]
  else path missing or not dir
    Fio-->>Caller: []
  end
  end
Loading
sequenceDiagram
  autonumber
  actor Caller
  participant FioTxt
  participant FS as FileSystem

  rect rgba(235,255,235,0.5)
  note over Caller,FioTxt: FioTxt.load(file_name, default_value=None)
  Caller->>FioTxt: load(file_name, None)
  FioTxt->>FioTxt: default_value := []
  FioTxt->>FS: exists(file_name)?
  alt file exists
    FS-->>FioTxt: open/read lines
    FioTxt-->>Caller: [lines]
  else missing
    FioTxt-->>Caller: []
  end
  end

  rect rgba(255,245,230,0.5)
  note over Caller,FioTxt: FioTxt.save(file_name, data)
  Caller->>FioTxt: save(file_name, list | str | None)
  FioTxt->>FioTxt: normalize to list of strings with \\n
  FioTxt->>FS: write lines
  FS-->>FioTxt: ok
  FioTxt-->>Caller: None/return
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20–30 minutes


📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 68ea2aa and 2f9203d.

📒 Files selected for processing (3)
  • deepmd/tf/nvnmd/utils/fio.py (5 hunks)
  • doc/model/train-fitting-tensor.md (1 hunks)
  • source/tests/tf/test_fio_utils.py (1 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch codex/fix-spelling-error-and-improve-tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@codecov
Copy link
Copy Markdown

codecov Bot commented Sep 4, 2025

Codecov Report

❌ Patch coverage is 71.42857% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 84.81%. Comparing base (c57d19f) to head (2f9203d).
⚠️ Report is 73 commits behind head on devel.

Files with missing lines Patch % Lines
deepmd/tf/nvnmd/utils/fio.py 71.42% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##            devel    #4960      +/-   ##
==========================================
+ Coverage   84.29%   84.81%   +0.52%     
==========================================
  Files         704      705       +1     
  Lines       68875    74498    +5623     
  Branches     3572     3573       +1     
==========================================
+ Hits        58057    63187    +5130     
- Misses       9678    10170     +492     
- Partials     1140     1141       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants